<?php
namespace Home\Model;

class WeightModel extends CommonModel{
    
    /**
     * 更新用户某一天的血压均值
     * $uid 用户id
     * $create_date 更新这一天的血压
     */
    public function updateWeightAverage($uid,$create_date){
        $list = array();$weightSum = 0;
        $list = $this->where(array('uid'=>$uid,'create_date'=>$create_date))->select();
        foreach($list as $v){
            $weightSum += $v['vol'];
        }
        $listCount = count($list);
        $vol_average = round(($weightSum/$listCount),1);
        $this->where(array('uid'=>$uid,'create_date'=>$create_date))->save(array('vol_average'=>$vol_average));
    }
    
}